home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_qt3.idb / usr / freeware / Qt / examples / splitter / splitter.cpp.z / splitter.cpp
C/C++ Source or Header  |  2002-04-08  |  3KB  |  101 lines

  1. /****************************************************************************
  2. ** $Id:  qt/splitter.cpp   3.0.3   edited Oct 12 12:18 $
  3. **
  4. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  5. **
  6. ** This file is part of an example program for Qt.  This example
  7. ** program may be used, distributed and modified without limitation.
  8. **
  9. *****************************************************************************/
  10.  
  11. #include <qapplication.h>
  12. #include <qlabel.h>
  13. #include <qsplitter.h>
  14. #include <qmultilineedit.h>
  15.  
  16. #include <qpainter.h>
  17.  
  18.  
  19. class Test : public QWidget {
  20. public:
  21.     Test(QWidget* parent=0, const char* name=0, int f=0);
  22.     void paintEvent(QPaintEvent* e);
  23. private:
  24. };
  25.  
  26.  
  27.  
  28. Test::Test(QWidget* parent, const char* name, int f) :
  29.     QWidget(parent, name, f)
  30. {
  31.  
  32. }
  33.  
  34. void Test::paintEvent(QPaintEvent* e)
  35. {
  36.     QPainter p(this);
  37.     p.setClipRect(e->rect());
  38.     const int d = 1000; //large number
  39.     int x1 = 0;
  40.     int x2 = width()-1;
  41.     int y1 = 0;
  42.     int y2 = height()-1;
  43.  
  44.     int x = (x1+x2)/2;
  45.     p.drawLine( x, y1, x+d, y1+d   );
  46.     p.drawLine( x, y1, x-d, y1+d   );
  47.     p.drawLine( x, y2, x+d, y2-d   );
  48.     p.drawLine( x, y2, x-d, y2-d   );
  49.  
  50.     int y = (y1+y2)/2;
  51.     p.drawLine( x1, y, x1+d, y+d   );
  52.     p.drawLine( x1, y, x1+d, y-d   );
  53.     p.drawLine( x2, y, x2-d, y+d   );
  54.     p.drawLine( x2, y, x2-d, y-d   );
  55. }
  56.  
  57.  
  58. int main( int argc, char ** argv )
  59. {
  60.     QApplication a( argc, argv );
  61.  
  62.     QSplitter *s1 = new QSplitter( QSplitter::Vertical, 0 , "main" );
  63.  
  64.     QSplitter *s2 = new QSplitter( QSplitter::Horizontal, s1, "top" );
  65.  
  66.     Test *t1 = new Test( s2, "topLeft" );
  67.     t1->setBackgroundColor( Qt::blue.light( 180 ) );
  68.     t1->setMinimumSize( 50, 0 );
  69.  
  70.     Test *t2 = new Test( s2, "topRight" );
  71.     t2->setBackgroundColor( Qt::green.light( 180 ) );
  72.     s2->setResizeMode( t2, QSplitter::KeepSize );
  73.     s2->moveToFirst( t2 );
  74.  
  75.     QSplitter *s3 = new QSplitter( QSplitter::Horizontal,  s1, "bottom" );
  76.  
  77.     Test *t3 = new Test( s3, "bottomLeft" );
  78.     t3->setBackgroundColor( Qt::red );
  79.     Test *t4 = new Test( s3, "bottomMiddle" );
  80.     t4->setBackgroundColor( Qt::white );
  81.  
  82.     Test *t5 = new Test( s3, "bottomRight" );
  83.     t5->setMaximumHeight( 250 );
  84.     t5->setMinimumSize( 80, 50 );
  85.     t5->setBackgroundColor( Qt::yellow );
  86.  
  87. #ifdef Q_WS_QWS
  88.     // Qt/Embedded XOR drawing not yet implemented.
  89.     s1->setOpaqueResize( TRUE );
  90. #endif
  91.     s2->setOpaqueResize( TRUE );
  92.     s3->setOpaqueResize( TRUE );
  93.  
  94.     a.setMainWidget( s1 );
  95.     s1->setCaption("Qt Example - Splitters");
  96.     s1->show();
  97.     int result = a.exec();
  98.     delete s1;
  99.     return result;
  100. }
  101.